/**
 * 首页模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	
	
	$(function(){
		$(document).on("focus","a,input:button,input:submit,button,input:checkbox,input:radio",function(){this.blur()});
		//首页鼠标进入三个上下结构的分类的动画
		$(document).on("mouseenter",".ldh-classExp-tb",function(){
			var _tHeight=$(this).innerHeight()*0.35,_bHeight=$(this).innerHeight()*0.65;
			$(this).addClass("opacity_9");
			$(this).find(".ldh-goodsClass-bBtm,.ldh-goodsClass-bTop p").hide();
			$(this).children(".ldh-goodsClass-t").animate({height:_tHeight},{duration:300,queue:false});
			$(this).children(".ldh-goodsClass-b").animate({height:_bHeight},{duration:300,queue:false});		
			$(this).find(".ldh-storeExp").animate({top:55},{duration:300,queue:false});
		})
		//首页鼠标离开三个上下结构的分类的动画
		.on("mouseleave",".ldh-classExp-tb",function(){
			var _height=$(this).innerHeight()*0.55,_tHeight=$(this).innerHeight()*0.45,_bHeight=$(this).innerHeight()*0.55;
			$(this).removeClass("opacity_9");
			$(this).children(".ldh-goodsClass-t").animate({height:_tHeight},{duration:300,queue:false});
			$(this).children(".ldh-goodsClass-b").animate({height:_bHeight},{duration:300,queue:false});
			$(this).find(".ldh-storeExp").animate({top:_height},{duration:300,queue:false});		
			$(this).find(".ldh-goodsClass-bBtm,.ldh-goodsClass-bTop p").show()
			//var _this=$(this);
			//setTimeout(function(){_this.stop(true,true);_this.find(".ldh-goodsClass-bBtm,.ldh-goodsClass-bTop p").show();},300);
		});
		//首页鼠标进入三个左右结构的分类的动画
		$(document).on("mouseenter",".ldh-classExp-rl",function(){
			if($(this).hasClass("class-food")){
				var _lWidth=$(this).innerWidth()*0.4,_rWidth=$(this).innerWidth()*0.6;
				$(this).addClass("opacity_9");
				$(this).find(".ldh-goodsClass-rBtm,.ldh-goodsClass-rTop p").hide();
				$(this).children(".ldh-goodsClass-l").animate({width:_lWidth},{duration:300,queue:false});
				$(this).children(".ldh-goodsClass-r").animate({width:_rWidth},{duration:300,queue:false});		
				$(this).find(".ldh-storeExp").animate({left:0},{duration:300,queue:false});
			}else{
				var _lWidth=$(this).innerWidth()*0.3,_rWidth=$(this).innerWidth()*0.7;
				$(this).addClass("opacity_9");
				$(this).find(".ldh-goodsClass-rBtm,.ldh-goodsClass-rTop p").hide();
				$(this).children(".ldh-goodsClass-l").animate({width:_lWidth},{duration:300,queue:false});
				$(this).children(".ldh-goodsClass-r").animate({width:_rWidth},{duration:300,queue:false});		
				$(this).find(".ldh-storeExp").animate({left:0},{duration:300,queue:false});	
			}
			
		})
		//首页鼠标离开三个左右结构的分类的动画
		.on("mouseleave",".ldh-classExp-rl",function(){
			if($(this).hasClass("class-food")){
				var _width=$(this).innerWidth()*0.5,_lWidth=$(this).innerWidth()*0.5,_rWidth=$(this).innerWidth()*0.5;
				$(this).removeClass("opacity_9");			
				$(this).children(".ldh-goodsClass-l").animate({width:_lWidth},{duration:300,queue:false});
				$(this).children(".ldh-goodsClass-r").animate({width:_rWidth},{duration:300,queue:false});		
				$(this).find(".ldh-storeExp").animate({left:_width},{duration:300,queue:false});
				$(this).find(".ldh-goodsClass-rBtm,.ldh-goodsClass-rTop p").show();
			}else{
				var _width=$(this).innerWidth()*0.6,_lWidth=$(this).innerWidth()*0.4,_rWidth=$(this).innerWidth()*0.6;
				$(this).removeClass("opacity_9");			
				$(this).children(".ldh-goodsClass-l").animate({width:_lWidth},{duration:300,queue:false});
				$(this).children(".ldh-goodsClass-r").animate({width:_rWidth},{duration:300,queue:false});		
				$(this).find(".ldh-storeExp").animate({left:_width},{duration:300,queue:false});
				$(this).find(".ldh-goodsClass-rBtm,.ldh-goodsClass-rTop p").show();
			}
			
		});
	});


	
	var base = require("../../custom/base/component-base.js");

	var async = require("../../custom/base/component-async.js");
	
	var validate = require("../../custom/base/component-validate.js");
	
	require("../../custom/base/component-md5.js");
	
	require("../../custom/base/component-map.js");
	
	base.init(base);
	
	base.initSearch();
	
	exports.init=function(m) {
		
		window.$ldh_index = m;
		
		var shopId=$("#session_shopid").val();
		
		var userId=$("#session_userid").val();
		
		base.setFromPage("index");
		
		base.getIsOpenShop(shopId);
		
		if(!validate.isNull(userId)){
			
			base.hasLoginShow(userId,$("#session_username").val(),$("#session_iconurl").val());
		}
	
		base.initMap();
		
		base.inputAdress();
		
		if(validate.isNull(base.getCookie("cityName"))){
			
			base.setCookie("cityId","440100");
			
			base.setCookie("cityName","广州市");
			
		}
		
		$("#cityName").html(base.getCookie("cityName"));
		
		if(validate.isNull(base.getCookie("address")) || validate.isNull(base.getCookie("lng")) || validate.isNull(base.getCookie("lat"))){
			
			base.myLocation();
		}else{
			
			$("#address").html(base.subString(base.getCookie("address"),10));
			
			$("#address").attr("title",base.getCookie("address"));
			
			base.myLocationHide();
			
			exports.getShopListByType();
			
			base.showCityPlaceholder();
			
		}
		
		base.getSearchHistoryCookie();
	};
	

	//根据分类查询商家
	exports.getShopListByType=function(position){
		
		var lng=base.getCookie("lng");
		
		var lat=base.getCookie("lat");
		
		var params={
			shopType:"1,2,3,4,5,50",		
			lng:lng,
			lat:lat
		};
	
		$("#shopType1_shopList,#shopType2_shopList,#shopType3_shopList,#shopType4_shopList,#shopType5_shopList,#shopType50_shopList").html('<div class="ldh-waiting" style="height:150px;"></div>');

		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/Shop/getShopListByType.do", params));
					
					if(data["code"]==1){
						
						
	
						for (var i = 0; i < data["shopList"].length; i++) {
								
								for(var j=0;j<data["shopList"][i].length;j++){
									
									
										var parentId=data["shopList"][i][j]["parentId"];
										
										var logoUrl=data["shopList"][i][j]["logoUrl"];
										
										var businessStatus=data["shopList"][i][j]["businessStatus"];
										
										var shopName=data["shopList"][i][j]["shopName"];
										
										if(logoUrl=="" || logoUrl.indexOf(".")<0){
											
											logoUrl= ctx+'/v1/img/category_f.png';
										}else{
											
											logoUrl=fileOpenUrl+logoUrl;
										} 
										
										if(businessStatus!="1"){
											
											businessStatus="休息中";
											
											shopName=base.subString(shopName,8);
											
										}else{
											
											businessStatus="";
										}
										$("#shopType"+parentId+"_shopList").append('<li onclick=$ldh_base.jumpToShopIndex("'+data["shopList"][i][j]["shopId"]+'")><span class="ldh-storeExp-pic"><img src="'+logoUrl+'"></span><span>'+shopName+'</span><span class="fl-right color_999" style="color:#ed5d3a;">'+businessStatus+'</span></li>');
							
								}
						}
						
						$("#shopType1_shopList,#shopType2_shopList,#shopType3_shopList,#shopType4_shopList,#shopType5_shopList,#shopType50_shopList").find(".ldh-waiting").remove();;

						
						if(validate.isNull($("#shopType1_shopList").html())){
							
							$("#shopType1_shopList").html("<li>&nbsp;&nbsp;附近没有该分类的商家</li>");
						}
						if(validate.isNull($("#shopType2_shopList").html())){
													
							$("#shopType2_shopList").html("<li>&nbsp;&nbsp;附近没有该分类的商家</li>");
						}
						if(validate.isNull($("#shopType3_shopList").html())){
							
							$("#shopType3_shopList").html("<li>&nbsp;&nbsp;附近没有该分类的商家</li>");
						}
						if(validate.isNull($("#shopType4_shopList").html())){
							
							$("#shopType4_shopList").html("<li>&nbsp;&nbsp;附近没有该分类的商家</li>");
						}
						if(validate.isNull($("#shopType5_shopList").html())){
							
							$("#shopType5_shopList").html("<li>&nbsp;&nbsp;附近没有该分类的商家</li>");
						}
						if(validate.isNull($("#shopType50_shopList").html())){
							
							$("#shopType50_shopList").html("<li>&nbsp;&nbsp;附近没有该分类的商家</li>");
						}
						
						
					}
					

					
					
					
				}))().start();
		
	};
	

	
});